/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chl.vrangogym.beans.backing;

import edu.chl.vrangogym.persistence.entities.Booking;
import edu.chl.vrangogym.persistence.entities.User;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author antonmalmquist
 */
@ManagedBean(name="Start")
@RequestScoped
public class StartPageBackingBean {

    private String firstName;
    private List<Booking> bookings;
    private User user;
    
    
    public void updateBookings() {
        bookings = (List<Booking>) user.getBookings();
    }

    public List<Booking> getBookings() {
        return bookings;
    }

    public void setBookings(List<Booking> bookings) {
        this.bookings = bookings;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    
    /** Creates a new instance of StartPageBackingBean */
    public StartPageBackingBean() {
    }
    
    @PostConstruct
    private void init() {
        user = (User)FacesContext.getCurrentInstance().getExternalContext()
                    .getSessionMap().get("Auth.user");
        if (user!=null){
            setFirstName(user.getContactInfo().getFirstName());
        }
        updateBookings();
    }
}
